﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Manager_Menu_Controls_UC_Themmenu : System.Web.UI.UserControl
{
    BUS_Menu data = new BUS_Menu();
    DTO_Menu obj = new DTO_Menu();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            txtTenmenu.Text = "";
            txtLink.Text = "";
        }
    }
    protected void drlDatmenu_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (drlDatmenu.SelectedItem.Value == "1")
        {
            lblMenucha.Visible = false;
            drlMenucha.Visible = false;
        }
        else
        {
            lblMenucha.Visible = true;
            drlMenucha.Visible = true;
            drlMenucha.DataSource = data.getMenu(2);
            drlMenucha.DataTextField = "Name";
            drlMenucha.DataValueField = "Id";
            drlMenucha.DataBind();
            drlMenucha.Items.Insert(0, "Mặc định");
            if (drlMenucha.SelectedValue == "Mặc định")
            {
                //drlMenucha.SelectedValue.ToString();
                //drlMenucha.DataValueField = "0";
                drlMenucha.SelectedItem.Value = "0";
            }
        }
    }
    protected void btnThemMenu_Click(object sender, EventArgs e)
    {
        obj.Name = txtTenmenu.Text;
        obj.Link = txtLink.Text;
        if (FileUpload1.HasFile)
        {
            FileUpload1.SaveAs(Server.MapPath("~/Images/" + FileUpload1.FileName));
            //obj.Img = FileUpload1.FileName;
        }
        if (FileUpload1.FileName.Length == 0)
        {
            obj.Img = "";
        }
        else
        {
            obj.Img = FileUpload1.FileName;
        }
        obj.Location = int.Parse(drlDatmenu.SelectedItem.Value);
        if (drlDatmenu.SelectedItem.Value == "1")
        {
            obj.Parent_Id = 0;

        }
        else
        {
            obj.Parent_Id = int.Parse(drlMenucha.SelectedItem.Value);
        }
        if (RdMo.Checked == true && RdDong.Checked == false)
        {
            obj.Status = true;
        }
        else
        {
            obj.Status = false;
        }
        //DAL_Menu a = new DAL_Menu();
        //Response.Write(a.Menu_Insert(obj));
        data.Menu_Insert(obj);
        Response.Redirect("Menu.aspx");
    }
}